package handler

import (
	"errors"
	"ulcdkey/conf"
	"ulcdkey/qyWechat"

	"github.com/labstack/echo/v4"
)

// 企业微信服务实例
var qyWx *qyWechat.QyWechat

func init() {
	loginInfo := conf.Conf.AgentList["Login"]

	if loginInfo == nil {

		panic(errors.New("login agent is nil"))
	}

	qyWx = qyWechat.New(conf.Conf.CorpId, loginInfo.Secret, conf.Conf.Token, conf.Conf.EncodingAESKey, loginInfo.AgentId)
	// 绑定文本消息回复事件
	qyWx.Add(map[string]string{"MsgType": "text"}, func(c qyWechat.Context) error {
		return c.Response().Text(c.Request().Content())
	})
}

// 大数据app 接收企业微信回调
func QyWxCallBack(c echo.Context) error {
	qyWx.Server(c.Response(), c.Request())
	return nil
}
